<?php

declare(strict_types=1);

namespace app\controller\api;

use app\model\AdminUser;
use app\util\Sms;
use app\util\Tools;
use think\facade\Db;
use think\Response;
use app\util\WechatService;
use app\model\AdminUserData;

/**
 * 驾校平台端学生管理
 */
class JxAdminStudent extends Base
{
    /**
     *
     *设置优惠券
     */
    public function setCoupon(): Response
    {
        $postData = $this->request->post();
        $admin_id = $postData['admin_id'];
        $coupon_name = $postData['coupon_name'];
        $coupon_amount = $postData['coupon_amount'];
        $coupon_day = $postData['coupon_day'];
        $coupon_type = $postData['coupon_type'];
        if($coupon_name == '' || $coupon_amount == '' || $coupon_day == '' || $coupon_type == ''){
            return $this->buildFailed(400, '参数错误');
        }
        $map['coupon_name'] = $coupon_name;
        $map['coupon_amount'] =  $coupon_amount;
        $map['coupon_day'] =  $coupon_day;
        $map['update_time'] = date('Y-m-d H:i:s',time());
        $res =Db::table('jx_coupon')->where('coupon_type',$coupon_type)->update($map);
        if ($res === false) {
            return $this->buildFailed(402, '修改失败');
        }
        return $this->buildSuccess();
    }


    /**
     *
     *获取优惠券信息
     */
    public function getCoupon(): Response
    {
        $postData = $this->request->post();
        $coupon_type = $postData['coupon_type'];
        $res =Db::table('jx_coupon')->where('coupon_type',$coupon_type)->find();
        if ($res === false) {
            return $this->buildFailed(402, '修改失败');
        }
        return $this->buildSuccess($res);
    }

}